package com.algrithom.recursive;

import com.util.CommonUtil;

import java.util.LinkedList;
import java.util.List;

public class Solution1 {
    public static void main(String[] args) {
        Solution1 solution1 = new Solution1();
        List<List<Integer>> result = solution1.subsets(new int[]{1,2,3});
        for (int i=0;i<result.size();i++) {
            System.out.println(result.get(i));
        }
    }

    private List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> result = new LinkedList<>();
        dfs(nums,0,new LinkedList<>(),result);
        return result;
    }

    private void dfs(int[] nums,int index,List<Integer> array,List<List<Integer>> result) {
        result.add(new LinkedList<>(array));
        for (int i=index;i<nums.length;i++) {
            if (array.contains(nums[i])) {
                continue;
            }
            array.add(nums[i]);
            dfs(nums,i + 1,array,result);
            array.remove(array.size() - 1);
        }
    }
}
